<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link rel="stylesheet" href="../../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="" lay-verify="required" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">档案编号</label>
                <div class="layui-input-block">
                    <input type="text" name="docNum"   lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>

        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="patientName"   lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-block">
                    <input type="number" name="patientAge"   autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">照片上传</label>
                <div class="layui-input-block">
                    <input type="text" name="patientPic"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <!--            <div class="layui-upload">-->
            <!--                <button type="button" class="layui-btn" id="test1">照片上传</button>-->
            <!--                <div class="layui-upload-list">-->
            <!--                    <img class="layui-upload-img" id="patientPic" style="width: 200px;height: 150px">-->
            <!--                    <p id="demoText"></p>-->
            <!--                </div>-->
            <!--            </div>-->
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="patientSex" value="1" title="男" >
                    <input type="radio" name="patientSex" value="0" title="女">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" name="patientTel"   autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">证件类型</label>
                <div class="layui-input-block">
                    <input type="text" name="cardType"    placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">证件号</label>
                <div class="layui-input-block">
                    <input type="text" name="cardNum"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">出生日期</label>
                <div class="layui-input-block">
                    <input type="date" name="birth"  lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">现住地址</label>
                <div class="layui-input-block">
                    <input type="text" name="address"     placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">民族</label>
                <div class="layui-input-block">
                    <input type="text" name="ethnic"   placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">籍贯</label>
                <div class="layui-input-block">
                    <input type="text" name="origin"   autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">婚姻状况</label>
                <div class="layui-input-block">
                    <input type="text" name="wedStatus"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">户口地址</label>
                <div class="layui-input-block">
                    <input type="text" name="accountAddress"     placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">社保类型</label>
                <div class="layui-input-block">
                    <input type="text" name="socialSecuritytype"   autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">社保卡号</label>
                <div class="layui-input-block">
                    <input type="text" name="socialSecuritynum"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">经济来源</label>
                <div class="layui-input-block">
                    <input type="text" name="financialFrom"   placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">付费方式</label>
                <div class="layui-input-block">
                    <input type="text" name="payWay" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">紧急联系人</label>
                <div class="layui-input-block">
                    <input type="text" name="emergencyContacts"     placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">紧急电话</label>
                <div class="layui-input-block">
                    <input type="text" name="emergencyTel"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>

        </div>

    </div>
    </div>
    </div>
    <div class="bottom">
        <div class="button-container " >
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" id="layui-icon layui-icon-ok" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm" id="layui-icon layui-icon-refresh">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../../component/layui/layui.js"></script>
<script src="../../../../component/pear/pear.js"></script>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        // 从 URL 中获取 id 参数的值
        function getUrlParam(name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
        var id = getUrlParam('id');

        // 页面加载时向后端发送请求获取需要回显的数据
        $.ajax({
            url: 'http://localhost:8080/oldinfo/queryById?id=' + id,
            type: 'get',
            beforeSend: function (xhr) {
                xhr.setRequestHeader('token', localStorage.getItem("token"));
            },
            success: function (res) {
                $("input[name='id']").val(res.data[0].id);
                $("input[name='docNum']").val(res.data[0].docNum);
                $("input[name='patientName']").val(res.data[0].patientName);
                $("input[name='patientAge']").val(res.data[0].patientAge);
                $("input[name='patientPic']").val(res.data[0].patientPic);
                $("input[name='patientSex'][value='" + res.data[0].patientSex + "']").prop('checked', true);
                // body.find("input[value="+data.patientSex+"]").attr("checked","checked");}
                $("input[name='patientTel']").val(res.data[0].patientTel);
                $("input[name='cardType']").val(res.data[0].cardType);
                $("input[name='cardNum']").val(res.data[0].cardNum);
                $("input[name='birth']").val(res.data[0].birth);
                $("input[name='address']").val(res.data[0].address);
                $("input[name='ethnic']").val(res.data[0].ethnic);
                $("input[name='origin']").val(res.data[0].origin);
                $("input[name='wedStatus']").val(res.data[0].wedStatus);
                $("input[name='accountAddress']").val(res.data[0].accountAddress);
                $("input[name='socialSecuritytype']").val(res.data[0].socialSecuritytype);
                $("input[name='socialSecuritynum']").val(res.data[0].socialSecuritynum);
                $("input[name='financialFrom']").val(res.data[0].financialFrom);
                $("input[name='payWay']").val(res.data[0].payWay);
                $("input[name='emergencyContacts']").val(res.data[0].emergencyContacts);
                $("input[name='emergencyTel']").val(res.data[0].emergencyTel);
                form.render()
                console.log(res.data)
            }
        });

        form.on('submit(user-save)', function (data) {
            $.ajax({
                url: 'http://localhost:8080/oldinfo/update',
                data: data.field,
                type: 'post',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('token', localStorage.getItem("token"));
                },
                success: function (result) {
                    console.log(result)
                    if (result.code == 0) {
                        layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.location.reload(); //数据刷新
                        });
                    } else {
                        layer.msg(result.msg, { icon: 2, time: 1000 });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>